package gw.com.android.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import www.com.library.view.RecyclerClickListener;

/**
 * BottomDialog基类，底部弹层
 * @author reeta
 *
 */
public class BaseBottomDialog extends Dialog{
	public Activity activity;
	protected TextView mTitleView;
	protected RecyclerView popListView;// pop上的listview
	protected View view = null;// 绑定显示视图的view
	protected RecyclerClickListener callback;// 点击事件的回调函数
	protected RecyclerView.Adapter modeListAdapter;
	protected static BaseBottomDialog mInstance = null;

	public BaseBottomDialog(Context context) {
		super(context, R.style.dialog_loading_bar_no_frame);
	}

	public static BaseBottomDialog instance(){
		return mInstance;
	}

	public void createPopWindow(View dialogView){

	}

	/**
	 * 初始化pop界面元素和数据
	 *
	 * @author reeta
	 */
	public void initPopWindow(final Activity activity, View editText,int layoutID,RecyclerClickListener callback) {
		this.activity = activity;
		this.view = editText;
		this.callback = callback;
		final LayoutInflater inflater = LayoutInflater.from(activity);
		final View dialogView = inflater.inflate(layoutID, null, false);
		setCancelable(true);
		setCanceledOnTouchOutside(true);
		createPopWindow(dialogView);

		ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
			/* The next line will add the ProgressBar to the dialog. */
		addContentView(dialogView, lp);

		Window window = getWindow();
		window.setGravity(Gravity.BOTTOM);
		window.getDecorView().setPadding(0, 0, 0, 0);
		WindowManager.LayoutParams lp2 = window.getAttributes();
		lp2.width = WindowManager.LayoutParams.MATCH_PARENT;
		lp2.height = WindowManager.LayoutParams.WRAP_CONTENT;
		window.setAttributes(lp2);
	}

	/**
	 * 返回弹层适配器
	 * @return
	 */
	public RecyclerView.Adapter getAdapter(){
		if(null != modeListAdapter){
			return modeListAdapter;
		}

		return null;
	}

	/**
	 * 返回当前pop是否显示状态
	 * 
	 * @author reeta
	 */
	public boolean hasShowing() {
		 return  isShowing();
	}

	/**
	 * 隐藏pop界面
	 * 
	 * @author reeta
	 */
	public void hidden() {
		mInstance = null;
		dismiss();
	}

}
